package com.heima.kafka.simple;

import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.springframework.web.bind.annotation.RestController;

import java.util.Properties;

public class KafkaProductorTest {
    public static void main(String[] args) {
        Properties properties = new Properties();
        // kafka 链接地址
        properties.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG,"192.168.56.136:9092");
        properties.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG,"org.apache.kafka.common.serialization.StringSerializer");
        properties.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG,"org.apache.kafka.common.serialization.StringSerializer");
        // 定义生产者
        KafkaProducer<String, String> kafkaProducer = new KafkaProducer<String, String>(properties);
        // 发送消息
//        ProducerRecord<String,String> producerRecord = new ProducerRecord<String,String>("item-topic","10000","hello");
        ProducerRecord<String,String> producerRecord = new ProducerRecord<String,String>("item-topic","hello");
        kafkaProducer.send(producerRecord);
        kafkaProducer.close();
    }
}
